package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizShopSpecs;
import com.member.shop.domain.SysBizTenantArea;
import com.member.shop.service.ISysBizTenantAreaService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【站点授权区域】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2025-01-08
 **/
@RestController
@RequestMapping("/shop/tenantArea")
public class SysBizTenantAreaController extends BaseController {
    @Resource
    private ISysBizTenantAreaService sysBizTenantAreaService;

    private void setTenantId(SysBizTenantArea sysBizTenantArea) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizTenantArea.setTenantId(tenantId);
        }
    }

    /**
     * 查询站点授权区域列表
     */
    @PreAuthorize("@ss.hasPermi('shop:tenantArea:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizTenantArea sysBizTenantArea) {
        startPage();
        setTenantId(sysBizTenantArea);
        List<SysBizTenantArea> list = sysBizTenantAreaService.selectSysBizTenantAreaList(sysBizTenantArea);
        return getDataTable(list);
    }

    /**
     * 导出站点授权区域列表
     */
    @PreAuthorize("@ss.hasPermi('shop:tenantArea:export')")
    @Log(title = "站点授权区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizTenantArea sysBizTenantArea) {
        setTenantId(sysBizTenantArea);
        List<SysBizTenantArea> list = sysBizTenantAreaService.selectSysBizTenantAreaList(sysBizTenantArea);
        ExcelUtil<SysBizTenantArea> util = new ExcelUtil<SysBizTenantArea>(SysBizTenantArea.class);
        util.exportExcel(response, list, "站点授权区域数据");
    }

    /**
     * 获取站点授权区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:tenantArea:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizTenantAreaService.selectSysBizTenantAreaById(id));
    }

    /**
     * 新增站点授权区域
     */
    @PreAuthorize("@ss.hasPermi('shop:tenantArea:add')")
    @Log(title = "站点授权区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizTenantArea sysBizTenantArea) {
        return toAjax(sysBizTenantAreaService.insertSysBizTenantArea(sysBizTenantArea));
    }

    /**
     * 修改站点授权区域
     */
    @PreAuthorize("@ss.hasPermi('shop:tenantArea:edit')")
    @Log(title = "站点授权区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizTenantArea sysBizTenantArea) {
        return toAjax(sysBizTenantAreaService.updateSysBizTenantArea(sysBizTenantArea));
    }

    /**
     * 删除站点授权区域
     */
    @PreAuthorize("@ss.hasPermi('shop:tenantArea:remove')")
    @Log(title = "站点授权区域", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizTenantAreaService.deleteSysBizTenantAreaByIds(ids));
    }
}
